class Solution(object):
    def canVisitAllRooms(self, rooms):
        """
        :type rooms: List[List[int]]
        :rtype: bool
        """
        n = len(rooms)
        p = [0] * n
        p[0] = 1
        now_set = {0}
        while now_set:
            next_set = set()
            for u in now_set:
                for v in rooms[u]:
                    if not p[v]:
                        p[v] = 1
                        next_set.add(v)
            now_set = next_set
        return all(p)



data = Solution()
rooms = [[1], [2], [3], []]
print(data.canVisitAllRooms(rooms))
